home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-PPC / IO.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  9KB  |  285 lines

  1. #ifndef _PPC_IO_H
  2. #define _PPC_IO_H
  3.  
  4. #include <linux/config.h>
  5. #include <asm/page.h>
  6. #include <asm/byteorder.h>
  7.  
  8. #define KERNELBASE    0xc0000000
  9.  
  10. #define SIO_CONFIG_RA    0x398
  11. #define SIO_CONFIG_RD    0x399
  12.  
  13. #define SLOW_DOWN_IO
  14.  
  15. #define PMAC_ISA_MEM_BASE     0
  16. #define PMAC_PCI_DRAM_OFFSET     0
  17. #define CHRP_ISA_IO_BASE     0xf8000000
  18. #define CHRP_ISA_MEM_BASE     0xf7000000
  19. #define CHRP_PCI_DRAM_OFFSET     0
  20. #define PREP_ISA_IO_BASE     0x80000000
  21. #define PREP_ISA_MEM_BASE     0xd0000000
  22. #define PREP_PCI_DRAM_OFFSET     0x80000000
  23.  
  24. #ifdef CONFIG_MBX
  25. #define _IO_BASE        0x80000000
  26. #define _ISA_MEM_BASE   0
  27. #define PCI_DRAM_OFFSET 0x80000000
  28. #else /* CONFIG_MBX8xx */
  29. #ifdef CONFIG_APUS
  30. #define _IO_BASE 0
  31. #define _ISA_MEM_BASE 0
  32. #define PCI_DRAM_OFFSET 0
  33. #else
  34. extern unsigned long isa_io_base;
  35. extern unsigned long isa_mem_base;
  36. extern unsigned long pci_dram_offset;
  37. #define _IO_BASE    isa_io_base
  38. #define _ISA_MEM_BASE    isa_mem_base
  39. #define PCI_DRAM_OFFSET    pci_dram_offset
  40. #endif /* CONFIG_APUS */
  41. #endif /* CONFIG_MBX8xx */
  42.  
  43. #define readb(addr) in_8((volatile unsigned char *)(addr))
  44. #define writeb(b,addr) out_8((volatile unsigned char *)(addr), (b))
  45. #if defined(CONFIG_APUS)
  46. #define readw(addr) (*(volatile unsigned short *) (addr))
  47. #define readl(addr) (*(volatile unsigned int *) (addr))
  48. #define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
  49. #define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
  50. #else
  51. #define readw(addr) in_le16((volatile unsigned short *)(addr))
  52. #define readl(addr) in_le32((volatile unsigned *)addr)
  53. #define writew(b,addr) out_le16((volatile unsigned short *)(addr),(b))
  54. #define writel(b,addr) out_le32((volatile unsigned *)(addr),(b))
  55. #endif
  56.  
  57. #define insb(port, buf, ns)    _insb((unsigned char *)((port)+_IO_BASE), (buf), (ns))
  58. #define outsb(port, buf, ns)    _outsb((unsigned char *)((port)+_IO_BASE), (buf), (ns))
  59. #define insw(port, buf, ns)    _insw((unsigned short *)((port)+_IO_BASE), (buf), (ns))
  60. #define outsw(port, buf, ns)    _outsw((unsigned short *)((port)+_IO_BASE), (buf), (ns))
  61. #define insl(port, buf, nl)    _insl((unsigned long *)((port)+_IO_BASE), (buf), (nl))
  62. #define outsl(port, buf, nl)    _outsl((unsigned long *)((port)+_IO_BASE), (buf), (nl))
  63.  
  64. #define inb(port)        in_8((unsigned char *)((port)+_IO_BASE))
  65. #define outb(val, port)        out_8((unsigned char *)((port)+_IO_BASE), (val))
  66. #if defined(CONFIG_APUS)
  67. #define inw(port)        in_be16((unsigned short *)((port)+_IO_BASE))
  68. #define outw(val, port)        out_be16((unsigned short *)((port)+_IO_BASE), (val))
  69. #define inl(port)        in_be32((unsigned *)((port)+_IO_BASE))
  70. #define outl(val, port)        out_be32((unsigned *)((port)+_IO_BASE), (val))
  71. #else
  72. #define inw(port)        in_le16((unsigned short *)((port)+_IO_BASE))
  73. #define outw(val, port)        out_le16((unsigned short *)((port)+_IO_BASE), (val))
  74. #define inl(port)        in_le32((unsigned *)((port)+_IO_BASE))
  75. #define outl(val, port)        out_le32((unsigned *)((port)+_IO_BASE), (val))
  76. #endif
  77.  
  78. #define inb_p(port)        in_8((unsigned char *)((port)+_IO_BASE))
  79. #define outb_p(val, port)    out_8((unsigned char *)((port)+_IO_BASE), (val))
  80. #define inw_p(port)        in_le16((unsigned short *)((port)+_IO_BASE))
  81. #define outw_p(val, port)    out_le16((unsigned short *)((port)+_IO_BASE), (val))
  82. #define inl_p(port)        in_le32(((unsigned *)(port)+_IO_BASE))
  83. #define outl_p(val, port)    out_le32((unsigned *)((port)+_IO_BASE), (val))
  84.  
  85. extern void _insb(volatile unsigned char *port, void *buf, int ns);
  86. extern void _outsb(volatile unsigned char *port, const void *buf, int ns);
  87. extern void _insw(volatile unsigned short *port, void *buf, int ns);
  88. extern void _outsw(volatile unsigned short *port, const void *buf, int ns);
  89. extern void _insl(volatile unsigned long *port, void *buf, int nl);
  90. extern void _outsl(volatile unsigned long *port, const void *buf, int nl);
  91.  
  92. /*
  93.  * The *_ns versions below don't do byte-swapping.
  94.  */
  95. #define insw_ns(port, buf, ns)    _insw_ns((unsigned short *)((port)+_IO_BASE), (buf), (ns))
  96. #define outsw_ns(port, buf, ns)    _outsw_ns((unsigned short *)((port)+_IO_BASE), (buf), (ns))
  97. #define insl_ns(port, buf, nl)    _insl_ns((unsigned long *)((port)+_IO_BASE), (buf), (nl))
  98. #define outsl_ns(port, buf, nl)    _outsl_ns((unsigned long *)((port)+_IO_BASE), (buf), (nl))
  99.  
  100. extern void _insw_ns(volatile unsigned short *port, void *buf, int ns);
  101. extern void _outsw_ns(volatile unsigned short *port, const void *buf, int ns);
  102. extern void _insl_ns(volatile unsigned long *port, void *buf, int nl);
  103. extern void _outsl_ns(volatile unsigned long *port, const void *buf, int nl);
  104.  
  105. #define memset_io(a,b,c)    memset((a),(b),(c))
  106. #define memcpy_fromio(a,b,c)    memcpy((a),(b),(c))
  107. #define memcpy_toio(a,b,c)    memcpy((a),(b),(c))
  108.  
  109. #ifdef __KERNEL__
  110. /*
  111.  * Map in an area of physical address space, for accessing
  112.  * I/O devices etc.
  113.  */
  114. extern void *__ioremap(unsigned long address, unsigned long size,
  115.                unsigned long flags);
  116. extern void *ioremap(unsigned long address, unsigned long size);
  117. #define ioremap_nocache(addr, size)    ioremap((addr), (size))
  118. extern void iounmap(void *addr);
  119. extern unsigned long iopa(unsigned long addr);
  120. #ifdef CONFIG_APUS
  121. extern unsigned long mm_ptov(unsigned long addr) __attribute__ ((const));
  122. #endif
  123.  
  124. /*
  125.  * The PCI bus is inherently Little-Endian.  The PowerPC is being
  126.  * run Big-Endian.  Thus all values which cross the [PCI] barrier
  127.  * must be endian-adjusted.  Also, the local DRAM has a different
  128.  * address from the PCI point of view, thus buffer addresses also
  129.  * have to be modified [mapped] appropriately.
  130.  */
  131. extern inline unsigned long virt_to_bus(volatile void * address)
  132. {
  133. #ifndef CONFIG_APUS
  134.         if (address == (void *)0)
  135.         return 0;
  136.         return (unsigned long)address - KERNELBASE + PCI_DRAM_OFFSET;
  137. #else
  138.     return iopa ((unsigned long) address);
  139. #endif
  140. }
  141.  
  142. extern inline void * bus_to_virt(unsigned long address)
  143. {
  144. #ifndef CONFIG_APUS
  145.         if (address == 0)
  146.         return 0;
  147.         return (void *)(address - PCI_DRAM_OFFSET + KERNELBASE);
  148. #else
  149.     return (void*) mm_ptov (address);
  150. #endif
  151. }
  152.  
  153. /*
  154.  * Change virtual addresses to physical addresses and vv, for
  155.  * addresses in the area where the kernel has the RAM mapped.
  156.  */
  157. extern inline unsigned long virt_to_phys(volatile void * address)
  158. {
  159. #ifndef CONFIG_APUS
  160.     return (unsigned long) address - KERNELBASE;
  161. #else
  162.     return iopa ((unsigned long) address);
  163. #endif
  164. }
  165.  
  166. extern inline void * phys_to_virt(unsigned long address)
  167. {
  168. #ifndef CONFIG_APUS
  169.     return (void *) (address + KERNELBASE);
  170. #else
  171.     return (void*) mm_ptov (address);
  172. #endif
  173. }
  174.  
  175. #endif /* __KERNEL__ */
  176.  
  177. /*
  178.  * Enforce In-order Execution of I/O:
  179.  * Acts as a barrier to ensure all previous I/O accesses have
  180.  * completed before any further ones are issued.
  181.  */
  182. extern inline void eieio(void)
  183. {
  184.     __asm__ __volatile__ ("eieio" : : : "memory");
  185. }
  186.  
  187. /* Enforce in-order execution of data I/O. 
  188.  * No distinction between read/write on PPC; use eieio for all three.
  189.  */
  190. #define iobarrier_rw() eieio()
  191. #define iobarrier_r()  eieio()
  192. #define iobarrier_w()  eieio()
  193.  
  194. /*
  195.  * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  196.  */
  197. extern inline int in_8(volatile unsigned char *addr)
  198. {
  199.     int ret;
  200.  
  201.     __asm__ __volatile__("lbz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
  202.     return ret;
  203. }
  204.  
  205. extern inline void out_8(volatile unsigned char *addr, int val)
  206. {
  207.     __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
  208. }
  209.  
  210. extern inline int in_le16(volatile unsigned short *addr)
  211. {
  212.     int ret;
  213.  
  214.     __asm__ __volatile__("lhbrx %0,0,%1; eieio" : "=r" (ret) :
  215.                   "r" (addr), "m" (*addr));
  216.     return ret;
  217. }
  218.  
  219. extern inline int in_be16(volatile unsigned short *addr)
  220. {
  221.     int ret;
  222.  
  223.     __asm__ __volatile__("lhz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
  224.     return ret;
  225. }
  226.  
  227. extern inline void out_le16(volatile unsigned short *addr, int val)
  228. {
  229.     __asm__ __volatile__("sthbrx %1,0,%2; eieio" : "=m" (*addr) :
  230.                   "r" (val), "r" (addr));
  231. }
  232.  
  233. extern inline void out_be16(volatile unsigned short *addr, int val)
  234. {
  235.     __asm__ __volatile__("sth%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
  236. }
  237.  
  238. extern inline unsigned in_le32(volatile unsigned *addr)
  239. {
  240.     unsigned ret;
  241.  
  242.     __asm__ __volatile__("lwbrx %0,0,%1; eieio" : "=r" (ret) :
  243.                  "r" (addr), "m" (*addr));
  244.     return ret;
  245. }
  246.  
  247. extern inline unsigned in_be32(volatile unsigned *addr)
  248. {
  249.     unsigned ret;
  250.  
  251.     __asm__ __volatile__("lwz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
  252.     return ret;
  253. }
  254.  
  255. extern inline void out_le32(volatile unsigned *addr, int val)
  256. {
  257.     __asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) :
  258.                  "r" (val), "r" (addr));
  259. }
  260.  
  261. extern inline void out_be32(volatile unsigned *addr, int val)
  262. {
  263.     __asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
  264. }
  265.  
  266. #ifdef __KERNEL__
  267. static inline int check_signature(unsigned long io_addr,
  268.     const unsigned char *signature, int length)
  269. {
  270.     int retval = 0;
  271.     do {
  272.         if (readb(io_addr) != *signature)
  273.             goto out;
  274.         io_addr++;
  275.         signature++;
  276.         length--;
  277.     } while (length);
  278.     retval = 1;
  279. out:
  280.     return retval;
  281. }
  282. #endif /* __KERNEL__ */
  283.  
  284. #endif
  285.